<?php
// +----------------------------------------------------------------------
// | 图片上传模型
// +----------------------------------------------------------------------
// | Copyright (c) 2015
// +----------------------------------------------------------------------
// | Author: baiping 125618036@qq.com http://www.webipcode.com
// +----------------------------------------------------------------------
// |2015-11-26 下午3:12:20
// +----------------------------------------------------------------------
defined('BASEPATH') OR exit('No direct script access allowed');

class Picture_model extends CI_Model{
	
	private $table_name;
	public function __construct(){
		$this->table_name = 'picture';
	}
	
	/**
	 * 添加数据
	 * @param array $data 数据
	 */
	public function addData($data){
		if ( empty($data) || !is_array( $data ) ){
			return false;
		}
		$query = $this->db->insert($this->table_name, $data);
		return $this->db->insert_id();
	}
	
	/**
	 * 获取单条数据
	 * @param array $where 获取条件
	 * @param string $field 获取字段
	 * @param int $limit 获取条数
	 */
	public function getFind($where, $field="path,id", $limit=1){
		if ( empty( $where ) ){
			return false;
		}
		$this->db->where($where);
		$this->db->select($field);
		$this->db->limit($limit);
		$res = $this->db->get( $this->table_name );
		return $res->row_array();
	}
	
	/**
	 * 删除数据操作
	 * @param unknown_type $where
	 */
	public function deleteData( $where ){
		if ( empty( $where ) || !is_array( $where ) ){
			return false;
		}
		foreach ( $where as $key => $val ){
			if ( is_array( $val ) ){
				$this->db->where_in($key, $val);
				unset($where[$key]);
			}else{
				$this->db->where($key, $val);
			}
		}
		return $this->db->delete( $this->table_name );
	}
}